package gases.as3.testing
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.utils.getTimer;
	
	import gases.as3.debug.DebugBase;
	import gases.as3.librarys.compnents.events.SkinEvent;
	import gases.as3.librarys.compnents.resource.MacroResourceManagaers;
	import gases.as3.librarys.compnents.skin.SkinStylesMangaer;
	import gases.as3.librarys.compnents.skin.SkinTransform;
	import gases.as3.librarys.compnents.skin.data.BaseSkin;
	import gases.as3.librarys.compnents.skin.transform.TransformXML;
	import gases.as3.librarys.compnents.swf.StyleConfig;
	import gases.as3.librarys.compnents.ui.control.GButton;

	public class TestingGButton extends DebugBase
	{
		public function TestingGButton()
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
//			var loader:Loader = new Loader();
//			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
//			loader.load(new URLRequest("assets/btnSkin.swf"));
			instance = StyleConfig.instance;
			instance.addEventListener(SkinEvent.LOAD_COMPLETE,onComplete);
		}
//		
		private function onComplete(e:Event):void
		{
//			
//			var swf:DisplayObject = LoaderInfo(e.target).content as DisplayObject;
//			MacroResourceManagaers.instance.UIResManager.setUISkinSwf(swf);
//			var transform:SkinTransform = new SkinTransform();
//			transform.setConfigTransform(new TransformXML());
//			transform.resloveSkinConfig(xml);
			
			
//			var skin:BaseSkin = SkinStylesMangaer.instance.getSkinData("green_btn") as BaseSkin;
			
			var skin:BaseSkin = instance.btnRedSkin;
			var t:int = getTimer();
//			_btn = new GButton("测试按钮");
//			_btn.skin = skin;
//			_btn.color = 0xFF0000;
//			this.addChild(_btn);
			
			var a:int;
			var b:int;
			for(var i:int = 0; i < 1000; i++)
			{
				_btn = new GButton();
				_btn.skin = skin;
				_btn.selectState = false;
				_btn.isSelect = false;
				_btn.x = a * 53;
				_btn.y = b * 25;
				this.addChild(_btn);
				a++;
				if(a == 28)
				{
					b++;
					a=0;
				}
			}
			trace(getTimer() - t);
			
		}
		
		private var instance:StyleConfig;
		private var _btn:GButton;
		private var xml:XML = <root xmlns:skin="gases.compnents.ui.skin">
									<skin:button type="button" scale9_top="5" scale9_left="5" scale9_right="5" scale9_bottom="5" skinname="green_btn" width="60" height="20">
										<styles stylesName="button_down" resName="btn_green_down"/>
										<styles stylesName="button_up" resName="btn_green_out"/>
										<styles stylesName="button_over" resName="btn_green_over"/>
										<styles stylesName="button_out" resName="btn_green_out"/>
									</skin:button>
									<skin:button type="button" scale9_top="5" scale9_left="5" scale9_right="5" scale9_bottom="5" skinname="red_btn" width="60" height="20">
										<styles stylesName="button_down" resName="btn_green_down"/>
										<styles stylesName="button_up" resName="btn_green_out"/>
										<styles stylesName="button_over" resName="btn_green_over"/>
										<styles stylesName="button_out" resName="btn_green_out"/>
									</skin>
								</root>;
	}
}





